package com.wwtech.epp.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;

import com.wwtech.epp.R;
import com.wwtech.epp.ui.activity.work.LargeTextActivity;

/**
 * Created by hu on 2017/10/23.
 */

public class LongClickTextView extends android.support.v7.widget.AppCompatTextView {
    Context context;
    public LongClickTextView(Context context) {
        super(context);
        init(context);
    }

    public LongClickTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public LongClickTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LargeTextActivity.class);
                intent.putExtra("content", getText());
                context.startActivity(intent);
//                ((Activity) context).overridePendingTransition(R.anim.main_activity_in, R.anim.splash_activity_out);
                ((Activity) context).overridePendingTransition(0,0);
            }
        });

//        setOnTouchListener(new OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                if (event.getAction() == MotionEvent.ACTION_DOWN) {
//                    startTime();
//                } else if (event.getAction() == MotionEvent.ACTION_UP) {
//                    handler.removeMessages(0);
//                    time = 0;
//                } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
//                    handler.removeMessages(0);
//                    time = 0;
//                }
//                return true;
//            }
//        });
    }
    double time = 0;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            time += 0.1;
            if (time >= 0.5) {
                time = 0;
                Intent intent = new Intent(context, LargeTextActivity.class);
                intent.putExtra("content", getText());
                context.startActivity(intent);
                ((Activity) context).overridePendingTransition(R.anim.main_activity_in, R.anim.splash_activity_out);
            } else {
                handler.sendEmptyMessageDelayed(0, 100);
            }
        }
    };
    private void startTime() {
        handler.sendEmptyMessageDelayed(0, 100);
    }
}
